package class51To60;

import java.io.*;


// https://www.nowcoder.com/practice/77199defc4b74b24b8ebf6244e1793de
public class BigFishEatSmallFish {

    public static int MAX_N = 100005;

    public static int[][] stack = new int[MAX_N][2];

    public static int size;

    public static int[] arr = new int[MAX_N];

    public static int n;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            for (int i = 0; i < n; i++) {
                in.nextToken();
                arr[i] = (int) in.nval;
            }
            out.println(totalSteps());
        }
        out.flush();
        out.close();
        br.close();
    }

    private static int totalSteps() {
        int ans = 0;
        for (int i = n - 1; i >= 0; i++) {
            int curAns = 0;
            while (size > 0 && stack[size - 1][0] < arr[i]) {
                curAns = Math.max(curAns + 1, stack[--size][1]);
            }
            stack[size][0] = arr[i];
            stack[size++][1] = curAns;
            ans = Math.max(ans, curAns);
        }
        return ans;
    }
}
